package com.example.itshome.activity;

import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.example.itshome.R;
import com.example.itshome.network.LoginRequest;
import com.example.itshome.onclick.OnClickTurnTo;

import java.lang.reflect.Field;
import java.util.Arrays;

public class LoginPageActivity extends AppCompatActivity {

    private Button loginButton;
    private Button registerButton;
    private EditText usernameEditText;
    private EditText passwordEditText;
    private Toast toast;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login_page);
        initFind();
        initButton();
        initToast();
    }

    void initFind(){
        loginButton=findViewById(R.id.btn_login_page_login);
        usernameEditText=findViewById(R.id.edt_login_page_username);
        passwordEditText=findViewById(R.id.edt_login_page_password);
        registerButton=findViewById(R.id.btn_login_page_register);
    }
    void initToast(){
        toast=new Toast(this);
    }

    void initButton(){
        loginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                LoginRequest request=new LoginRequest(LoginPageActivity.this)
                        .setToast(toast)
                        .setUsername(usernameEditText.getText().toString())
                        .setPassword(passwordEditText.getText().toString())
                        .setClicker(loginButton);
                request.start();
            }
        });
        registerButton.setOnClickListener(new OnClickTurnTo(LoginPageActivity.this,RegisterPageActivity.class));
    }
}